package model

import (
	"gorm.io/gorm"
	__ "video-srv/basic/proto/rpc"
)

type Episode struct {
	gorm.Model
	VideoId      int    `gorm:"type:int" json:"videoId"`
	Title        string `gorm:"type:varchar(30)" json:"title"`
	Duration     int    `gorm:"type:int" json:"duration"`
	VideoUrl     string `gorm:"type:varchar(255)" json:"videoUrl"`
	EpisodeOrder int    `gorm:"type:int" json:"episodeOrder"`
	Refer        string `gorm:"type:varchar(30)" json:"refer"`  //简介
	AuthEr       string `gorm:"type:varchar(30)" json:"authEr"` //作者
	LookCount    int    `gorm:"type:int" json:"lookCount"`
	LikeCount    int    `gorm:"type:int" json:"likeCount"`
	CommentCount int    `gorm:"type:int" json:"commentCount"`
	CollectCount int    `gorm:"type:int" json:"collectCount"`
	IsFree       int    `gorm:"type:int" json:"isFree"` //是否免费
}

func (e *Episode) GetEpisodeById(db *gorm.DB, id int) (list []*__.EpisodeList, err error) {
	err = db.Model(&e).
		Select("videos.title,image,tags,videos.refer,area_name,category_name,channel_name,year_name,auth_er,look_count,like_count,comment_count,collect_count").
		Joins("LEFT JOIN videos on videos.id = episodes.video_id").
		Where("videos.id = ?", id).Find(&list).Error
	return
}

func (e *Episode) GetEpisodeList(db *gorm.DB, id int) (err error) {
	err = db.
		Select("title,duration,episode_order,refer,auth_er,look_count,like_count,comment_count,collect_count,is_free").
		Where("video_id = ?", id).Find(&e).Error
	return err
}
